package com.sgb.kjwl.view.ui.adapter.self.logistics;

import android.text.TextUtils;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.CargoPublishEntity;
import com.sgb.kjwl.model.entity.transport.SingleItemConstant;

import java.util.List;

/**
 * 发布货源发货人/收货人适配器
 */
public class CargoPublishPersonAdapter extends BaseMultiItemQuickAdapter<CargoPublishEntity.LocationEntity, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public CargoPublishPersonAdapter(List<CargoPublishEntity.LocationEntity> data) {
        super(data);
        //ship
        addItemType(SingleItemConstant.TYPE_ONE, R.layout.item_cargo_publish_person_ship_head);
        addItemType(SingleItemConstant.TYPE_TWO, R.layout.item_cargo_publish_person_ship_sub);
        //receipt
        addItemType(SingleItemConstant.TYPE_THREE, R.layout.item_cargo_publish_person_receipt_sub);
        addItemType(SingleItemConstant.TYPE_FOUR, R.layout.item_cargo_publish_person_receipt_footer);
    }

    @Override
    protected void convert(BaseViewHolder helper, CargoPublishEntity.LocationEntity item) {
        //设置地址
        if (TextUtils.isEmpty(item.getProvince())) {
            helper.setText(R.id.tv_item_cpp_address, "");
        } else {
            helper.setText(R.id.tv_item_cpp_address, String.format("%s%s%s%s",
                    item.getProvince(),
                    item.getCity(),
                    item.getDistrict(),
                    item.getAddress()));
        }
        //设置联系人
        StringBuilder builder = new StringBuilder();
        if (!TextUtils.isEmpty(item.getContact())) {
            builder.append("/").append(item.getContact());
        }
        if (!TextUtils.isEmpty(item.getTelPhone())) {
            builder.append("/").append(item.getTelPhone());
        }
        helper.setText(R.id.tv_item_cpp_person, builder.length() > 0
                ? builder.substring(1)
                : "");
    }
}
